package com.megic.controller;

import com.megic.client.ProductClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @Author Gene
 * @Date 2020/8/8 20:48
 * @Version 1.0
 */
@RestController
@Slf4j
public class UserController {

    @Autowired
    RestTemplate restTemplate;

    @Bean
    @LoadBalanced
    RestTemplate restTemplate(RestTemplateBuilder builder){
        return  builder.build();
    }

    @Autowired
    ProductClient productClient;

    @GetMapping("/user/getProductInfo")
    public Map<String,Object> getProductInfo(@RequestParam(value = "productId",required = false) String id){
        System.out.println("我的id[{}]"+id);
//        return  restTemplate.getForObject("http://products/product/findall?productId="+id,String.class);
        Map<String,Object> map=productClient.findall(id);
        log.info("我的结果是[{}]",map);
        return map;
    }
}
